package com.crawler.harbour.controller;


import java.io.IOException;
import java.lang.reflect.Field;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.crawler.harbour.common.Result;
import com.crawler.harbour.dto.ContainerInfo;
import com.crawler.harbour.dto.ContainerInfoList;
import com.crawler.harbour.dto.DaZhaKouImportDto;
import com.crawler.harbour.dto.DaZhaKouOutDto;
import com.crawler.harbour.dto.ImportContainerInfo;
import com.crawler.harbour.dto.ImportTrailerNumberInfo;
import com.crawler.harbour.dto.ReportDto;
import com.crawler.harbour.dto.TrafficInformation;
import com.crawler.harbour.dto.TrailerNumberInfo;
import com.crawler.harbour.exception.SimpleException;
import com.crawler.harbour.utils.LoginUtil;
import com.crawler.harbour.utils.StringUtils;
import com.crawler.harbour.utils.UrlUtil;
import com.google.common.collect.Lists;

import net.dongliu.requests.Cookie;
import net.dongliu.requests.Parameter;
import net.dongliu.requests.Requests;
import net.dongliu.requests.Response;
import net.dongliu.requests.Session;
/**
 * 报备接口
 * @author czj
 *
 */
@RestController
@RequestMapping(value = "/crawler")
public class XMFTZController {

    private static final Logger LOGGER = LoggerFactory.getLogger(XMFTZController.class);
    private static Map<String,String> dockMap = new HashMap<String, String>();
    static {
		dockMap.put("HRD", "PHR");
		dockMap.put("SYT", "PSY");
		dockMap.put("H.C", "PGJ");
		dockMap.put("XHD", "PHD");
		dockMap.put("YHT", "PYH");
    }
    /**
     * 进/出口报备总接口
     * @param reportDto
     * @return
     */
    @RequestMapping(value = "report", method = RequestMethod.POST)
    public Object report(@RequestBody ReportDto reportDto) {
    	try {
    		reportDto.setPort(dockMap.get(reportDto.getPort()));
    		 if(reportDto.getTradeType().equals("BIZT0001")||reportDto.getTradeType().equals("BIZT0003"))
    	 	    {
    	 	    	//外贸出口
    	    		 DaZhaKouOutDto daZhaKouOutDto = new DaZhaKouOutDto(); 
    	    		 daZhaKouOutDto.setBusinessType("1");
    	    		 ContainerInfo containerInfo = new ContainerInfo();
    	    		 TrailerNumberInfo trailerNumberInfo = new TrailerNumberInfo();
    	    		 trailerNumberInfo.setVehicleno(reportDto.getCarNo());
    	    		 trailerNumberInfo.setDockCode(reportDto.getPort());
    	    		 trailerNumberInfo.setSealno(reportDto.getSealNo());
    	    		 containerInfo.setCntrno(reportDto.getContainerNo());  
    	    		 containerInfo.setSealno(reportDto.getSealNo());
    	    		 containerInfo.setSizetypeofcntr(reportDto.getContainerInfo());
    	    		 containerInfo.setCntrWeight(reportDto.getTare());
    	    		 daZhaKouOutDto.setUserName(reportDto.getUserName());
    	    		 daZhaKouOutDto.setPassword(reportDto.getPassword());
    	    		 daZhaKouOutDto.setTrailerNumberInfo(trailerNumberInfo);
    	    		 daZhaKouOutDto.setContainerInfo(containerInfo);
    	 	    	return  danxiang(daZhaKouOutDto);
    	 	    }else if(reportDto.getTradeType().equals("BIZT0002")||reportDto.getTradeType().equals("BIZT0004")) {
    	 	    	//外贸进口
    	 	    	DaZhaKouImportDto daZhaKouImportDto = new DaZhaKouImportDto();
    	 	    	ImportContainerInfo importContainerInfo = new ImportContainerInfo();
    	 	    	ImportTrailerNumberInfo importTrailerNumberInfo = new ImportTrailerNumberInfo(); 	    	
    	 	    	importTrailerNumberInfo.setVehicleno(reportDto.getCarNo());
    	 	    	importContainerInfo.setLadingBillNo(reportDto.getLadingBillNo());
    	 	    	importContainerInfo.setCntrno(reportDto.getContainerNo());
    	 	    	importTrailerNumberInfo.setDockCode(reportDto.getPort());
    	 	    	importContainerInfo.setSealno(reportDto.getSealNo());
    	 	    	importContainerInfo.setSizetypeofcntr(reportDto.getContainerInfo());
    	   	    	importContainerInfo.setCntrWeight(reportDto.getTare());
    	 	    	daZhaKouImportDto.setUserName(reportDto.getUserName());
    	 	    	daZhaKouImportDto.setPassword(reportDto.getPassword());
    	 	    	daZhaKouImportDto.setImportContainerInfo(importContainerInfo);
    	 	    	daZhaKouImportDto.setImportTrailerNumberInfo(importTrailerNumberInfo);
    	 	    	return danxiangImport(daZhaKouImportDto);
    	 	    }else if(reportDto.getTradeType().equals("BIZT0000")) {
    	 	    	return rugang(reportDto);
    	 	    }else {
    	 	    	return new Result("error", "进出口类型参数错误");
    	 	    }	
    	}catch (Exception e) {
    		return new Result("error", "操作失败，可能是验证码识别错误");
		}
    	//return null;
    }
    
    /**
     * 车牌号码查询
     *
     * @param vehicleno
     * @return
     */
    @RequestMapping(value = "trailerNumberInfo", method = RequestMethod.POST)
    public Object trailerNumberInfo(String vehicleno) {
        try {
            Session session = Requests.session();
            Response<String> card = session.post(UrlUtil.TRAILERNUMBERINFO + System.currentTimeMillis()).verify(false).forms(new Parameter("vehicleno", vehicleno)).send().toTextResponse();
            LOGGER.info("trailerNumberInfo_result:" + card.getBody());
            return card.getBody();
        } catch (Exception e) {
            throw new SimpleException("车牌号码查询出错");
        }
    }

    /**
     * 车架类型
     *
     * @return
     */
    @RequestMapping(value = "trailerNumberInfoBD", method = RequestMethod.GET)
    public Object trailerNumberInfoBD() {
        try {
            Session session = Requests.session();
            Response<String> response = session.get(UrlUtil.TRAILERNUMBERINFOBD).send().toTextResponse();
            LOGGER.info("trailerNumberInfoBD_result:" + response.getBody());
            return response.getBody();
        } catch (Exception e) {
            throw new SimpleException("车架类型获取出错");
        }
    }

    /**
     * 尺寸/箱型代码猜测
     *
     * @return
     */
    @RequestMapping(value = "tbcodecntrts", method = RequestMethod.POST)
    public Object tbcodecntrts(@RequestParam("query") String query) {
        try {
            query = URLEncoder.encode(query, "utf-8");
            Session session = Requests.session();
            Response<String> response = session.get(UrlUtil.TBCODECNTRTS + query + "&timestamp=" + System.currentTimeMillis()).send().toTextResponse();
            LOGGER.info("tbcodecntrts_result:" + response.getBody());
            return response.getBody();
        } catch (Exception e) {
            throw new SimpleException("尺寸/箱型代码猜测出错");
        }
    }
    
    /**
     * 大闸口  出口保存
     *
     * @param daZhaKouOutDto  msgStatus的值为0表示只保存，值为1表示保存并发送
     * @return
     */
    private Object danxiang(DaZhaKouOutDto daZhaKouOutDto) {
        Session session = LoginUtil.daZhaKouPreLogin(daZhaKouOutDto.getUserName(),daZhaKouOutDto.getPassword());
        session.get("https://www.china-xmftz.gov.cn/views/app/goto.aspx?id=24" ).send().toTextResponse();
        //查询车牌号
        String vehicleno = daZhaKouOutDto.getTrailerNumberInfo().getVehicleno();
        Response<String> card = session.post("https://tqbb.china-xmftz.gov.cn:8099/TrailerNumberInfo.ashx?__method=t&d=" + System.currentTimeMillis()).verify(false).forms(new Parameter("vehicleno", vehicleno)).send().toTextResponse();
        System.out.println(card.getBody());
        JSONObject cardResult = null;
        try {
            cardResult = JSONObject.parseObject(card.getBody());
        } catch (Exception e) {
            throw new SimpleException("查询车牌号出错");
        }
        Map<String, Object> TbtrailerResult = (Map<String, Object>) cardResult.get("TbtrailerResult");
        TrailerNumberInfo trailerNumberInfo = daZhaKouOutDto.getTrailerNumberInfo();
        ContainerInfo containerInfo = daZhaKouOutDto.getContainerInfo();
        daZhaKouOutDto.setDockCode(trailerNumberInfo.getDockCode());
        trailerNumberInfo.setMsgStatus("0");
        trailerNumberInfo.setCntrNo(containerInfo.getCntrno());
        trailerNumberInfo.setRfidSerialno(TbtrailerResult.get("RfidSerialNo") == null ? "" : TbtrailerResult.get("RfidSerialNo").toString());
        trailerNumberInfo.setCorpname(TbtrailerResult.get("CorpnameS") == null ? "" : TbtrailerResult.get("CorpnameS").toString());
        trailerNumberInfo.setCorpno(TbtrailerResult.get("CorpnameL") == null ? "" : TbtrailerResult.get("CorpnameL").toString());

        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("trailerNumberInfo.cntrNo", trailerNumberInfo.getCntrNo());
        paramMap.put("trailerNumberInfo.sealno", trailerNumberInfo.getSealno());
        paramMap.put("trailerNumberInfo.yardCode", trailerNumberInfo.getYardCode());
        paramMap.put("trailerNumberInfo.customsCode", trailerNumberInfo.getCustomsCode());
        paramMap.put("RanNum", "");
        paramMap.put("trailerNumberInfo.msgStatus", trailerNumberInfo.getMsgStatus()==null?"0":trailerNumberInfo.getMsgStatus());//msgStatus的值为0表示只保存，值为1表示保存并发送
        paramMap.put("trailerNumberInfo.addedFlag", trailerNumberInfo.getAddedFlag()==null?"0":trailerNumberInfo.getAddedFlag());
        
        paramMap.put("trailerNumberInfo.dockCode", trailerNumberInfo.getDockCode());
        paramMap.put("trailerNumberInfo.corpname", trailerNumberInfo.getCorpname());
        paramMap.put("trailerNumberInfo.corpno", trailerNumberInfo.getCorpno());
        paramMap.put("trailerNumberInfo.vehicleno", trailerNumberInfo.getVehicleno());
        paramMap.put("trailerNumberInfo.trailerWeight", trailerNumberInfo.getTrailerWeight());
        paramMap.put("trailerNumberInfo.rfidSerialno", trailerNumberInfo.getRfidSerialno());
        paramMap.put("trailerNumberInfo.trailerFrameWeight", trailerNumberInfo.getTrailerFrameWeight());
        paramMap.put("trailerNumberInfo.tfcode1", trailerNumberInfo.getTfcode1());
        paramMap.put("trailerNumberInfo.tfcode", trailerNumberInfo.getTfcode());
        paramMap.put("trailerNumberInfo.typedescription", trailerNumberInfo.getTypedescription());
        paramMap.put("trailerNumberInfo.remark", trailerNumberInfo.getRemark());
        paramMap.put("BusinessType", daZhaKouOutDto.getBusinessType()==null?"0":daZhaKouOutDto.getBusinessType());
        
        paramMap.put("containerInfo.eirno", containerInfo.getEirno());
        paramMap.put("containerInfo.eirinfoExist", containerInfo.getEirinfoExist()==null?"0":containerInfo.getEirinfoExist());
        paramMap.put("containerInfo.cntrno", containerInfo.getCntrno());
        paramMap.put("containerInfo.sealno", containerInfo.getSealno());
        paramMap.put("containerInfo.sizetypeofcntr", containerInfo.getSizetypeofcntr());
        paramMap.put("containerInfo.cntrWeight", containerInfo.getCntrWeight());
        
        
        paramMap.put("dockCode", daZhaKouOutDto.getDockCode());
        paramMap.put("TrailsInfo", daZhaKouOutDto.getTrailsInfo());
        paramMap.put("Cno", daZhaKouOutDto.getCno());
        paramMap.put("UserId", daZhaKouOutDto.getUserId());
        paramMap.put("CnoName", daZhaKouOutDto.getCnoName());
        
        paramMap.put("__method", "c");
        paramMap.put("cntrnoStatus", 1);
        //URL参数cntrnoStatus=0为派车，1为已提重箱
        Map<String, Object> headMap = new HashMap<>();
        headMap.put("Referer", "https://tqbb.china-xmftz.gov.cn:8099/TrailerNumberInfoAdd.aspx");
        headMap.put("Origin", "https://tqbb.china-xmftz.gov.cn:8099");       
        Response<String> export = session.post("https://tqbb.china-xmftz.gov.cn:8099/TrailerNumberInfo.ashx?__method=c&cntrnoStatus=1").headers(headMap).body(paramMap).send().toTextResponse();
        System.out.println(export.getBody());

        JSONObject exportResult = null;
        try {
            exportResult = JSONObject.parseObject(export.getBody());
            resultConvert(exportResult);
        } catch (Exception e) {
            throw new SimpleException("保存出错");
        }
        return exportResult;
    }

    private void resultConvert(JSONObject exportResult) {
    	if(exportResult!=null) {
    		exportResult.put("result", exportResult.get("Result"));
            exportResult.put("message", exportResult.get("Message"));
            exportResult.remove("Result");
            exportResult.remove("Message");
    	}
    }

    /**
     * 大闸口  进口保存
     *
     * @param daZhaKouImportDto  msgStatus的值为0表示只保存，值为1表示保存并发送
     * @return
     */
    private Object danxiangImport(DaZhaKouImportDto daZhaKouImportDto) {
    	 Session session = LoginUtil.daZhaKouPreLogin(daZhaKouImportDto.getUserName(),daZhaKouImportDto.getPassword());
        //查询车牌号
        String vehicleno = daZhaKouImportDto.getImportTrailerNumberInfo().getVehicleno();
        Response<String> card = session.post("https://tqbb.china-xmftz.gov.cn:8099/ImportTrailerNumberInfo.ashx?__method=t&d=" + System.currentTimeMillis()).verify(false).forms(new Parameter("vehicleno", vehicleno)).send().toTextResponse();
        System.out.println(card.getBody());
        JSONObject cardResult = null;
        try {
            cardResult = JSONObject.parseObject(card.getBody());
        } catch (Exception e) {
            throw new SimpleException("查询车牌号出错");
        }
        Map<String, Object> TbtrailerResult = (Map<String, Object>) cardResult.get("TbtrailerResult");

        ImportTrailerNumberInfo importTrailerNumberInfo = daZhaKouImportDto.getImportTrailerNumberInfo();
        ImportContainerInfo importContainerInfo = daZhaKouImportDto.getImportContainerInfo();
        String dockCode = daZhaKouImportDto.getDockCode();
        importContainerInfo.setSealno(importContainerInfo.getSealno());

        importTrailerNumberInfo.setTrailerWeight(TbtrailerResult.get("Weight") == null ? "" : TbtrailerResult.get("Weight").toString());
        importTrailerNumberInfo.setRfidSerialno(TbtrailerResult.get("RfidSerialNo") == null ? "" : TbtrailerResult.get("RfidSerialNo").toString());
        importTrailerNumberInfo.setCorpname(TbtrailerResult.get("CorpnameS") == null ? "" : TbtrailerResult.get("CorpnameS").toString());
        importTrailerNumberInfo.setCorpno(TbtrailerResult.get("CorpnameL") == null ? "" : TbtrailerResult.get("CorpnameL").toString());
        importTrailerNumberInfo.setDockCode(dockCode);
        importTrailerNumberInfo.setAddedFlag("0");
        importTrailerNumberInfo.setCntrNo(importContainerInfo.getCntrno());
        importTrailerNumberInfo.setSealno(importContainerInfo.getSealno());
        importTrailerNumberInfo.setMsgStatus("0");////msgStatus的值为0表示只保存，值为1表示保存并发送
        importTrailerNumberInfo.setCustomsCode("3708");
        
        importTrailerNumberInfo.setTfcode1("05,5000,40’两排轮普通架");
        importTrailerNumberInfo.setTfcode("05");
        importTrailerNumberInfo.setTypedescription("40’两排轮普通架");
        importTrailerNumberInfo.setTrailerWeight("5000");

        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("importTrailerNumberInfo.cntrNo", importTrailerNumberInfo.getCntrNo());
        paramMap.put("importTrailerNumberInfo.sealno", importTrailerNumberInfo.getSealno());
        paramMap.put("importTrailerNumberInfo.customsCode", importTrailerNumberInfo.getCustomsCode());
        paramMap.put("importTrailerNumberInfo.grossweight", importTrailerNumberInfo.getGrossweight());
        paramMap.put("importTrailerNumberInfo.msgStatus", importTrailerNumberInfo.getMsgStatus()==null?"0":importTrailerNumberInfo.getMsgStatus());//msgStatus的值为0表示只保存，值为1表示保存并发送
        paramMap.put("importTrailerNumberInfo.addedFlag", importTrailerNumberInfo.getAddedFlag()==null?"0":importTrailerNumberInfo.getAddedFlag());
        paramMap.put("importTrailerNumberInfo.dockCode", importTrailerNumberInfo.getDockCode());

        paramMap.put("importTrailerNumberInfo.corpname", importTrailerNumberInfo.getCorpname());
        paramMap.put("importTrailerNumberInfo.corpno", importTrailerNumberInfo.getCorpno());
        paramMap.put("importTrailerNumberInfo.vehicleno", importTrailerNumberInfo.getVehicleno());
        paramMap.put("importTrailerNumberInfo.trailerWeight", importTrailerNumberInfo.getTrailerWeight());
        paramMap.put("importTrailerNumberInfo.rfidSerialno", importTrailerNumberInfo.getRfidSerialno());
        paramMap.put("importTrailerNumberInfo.trailerFrameWeight", importTrailerNumberInfo.getTrailerFrameWeight());
        paramMap.put("importTrailerNumberInfo.tfcode1", importTrailerNumberInfo.getTfcode1());
        paramMap.put("importTrailerNumberInfo.tfcode", importTrailerNumberInfo.getTfcode());
        paramMap.put("importTrailerNumberInfo.typedescription", importTrailerNumberInfo.getTypedescription());
        paramMap.put("importTrailerNumberInfo.remark", importTrailerNumberInfo.getRemark());
        
        paramMap.put("importContainerInfo.billNo", importContainerInfo.getLadingBillNo());
        paramMap.put("importContainerInfo.eirno", importContainerInfo.getEirno());
        paramMap.put("importContainerInfo.eirinfoExist", importContainerInfo.getEirinfoExist());
        paramMap.put("importContainerInfo.cntrno", importContainerInfo.getCntrno());
        paramMap.put("importContainerInfo.sealno", importContainerInfo.getSealno());
        paramMap.put("importContainerInfo.sizetypeofcntr", importContainerInfo.getSizetypeofcntr());
        paramMap.put("importContainerInfo.cntrWeight", importContainerInfo.getCntrWeight());
        
        paramMap.put("dockCode", importTrailerNumberInfo.getDockCode());
        
        Map<String, Object> headMap = new HashMap<>();
        headMap.put("Referer", "https://tqbb.china-xmftz.gov.cn:8099/ImportTrailerNumberInfoAdd.aspx");
        headMap.put("Origin", "https://tqbb.china-xmftz.gov.cn:8099");
        //URL参数cntrnoStatus=0为派车 为1是已提重箱
        Response<String> export = session.post("https://tqbb.china-xmftz.gov.cn:8099/ImportTrailerNumberInfo.ashx?__method=c&cntrnoStatus=1").headers(headMap).body(paramMap).send().toTextResponse();
        System.out.println(export.getBody());

        JSONObject exportResult = null;
        try {
            exportResult = JSONObject.parseObject(export.getBody());
            resultConvert(exportResult);
        } catch (Exception e) {
            throw new SimpleException("保存出错");
        }
        return exportResult;
    }

  

    /**
     * 入港信息报备  检查 保存 检查并发送
     *
     * @return
     * @throws IOException
     */
    private Object rugang(ReportDto reportDto) {
    	TrafficInformation information = new TrafficInformation();
    	information.setBusinessType("1");
    	ContainerInfo containerInfo =new ContainerInfo();
    	ContainerInfoList containerInfos =new ContainerInfoList();    	
    	information.setCno(reportDto.getContainerNo());
    	information.setDockCode(reportDto.getPort());
    	information.setVehicleno(reportDto.getCarNo());
    	
    	containerInfo.setCntrno(reportDto.getContainerNo());
    	containerInfo.setSealno(reportDto.getSealNo());
    	containerInfo.setSizetypeofcntr(reportDto.getContainerInfo());
        containerInfo.setCntrWeight(reportDto.getTare());
        containerInfos.setContainerInfos(Lists.newArrayList(containerInfo,new ContainerInfo()));
    	
        try {
            String body= getParamBody(information,containerInfos);
            Session session = LoginUtil.daZhaKouPreLogin(reportDto.getUserName(),reportDto.getPassword());
            String url=UrlUtil.RUGANG + information.getMethod();
            if(StringUtils.isNotBlank(information.getCntrnoStatus())){
                url+="&cntrnoStatus="+information.getCntrnoStatus();
            }
            System.out.println(body);
            Response<String> export = session.post(url).headers(Parameter.of("Content-Type", "application/x-www-form-urlencoded")).body(body).send().toTextResponse();
            LOGGER.info("rugang_result:" + export.getBody());
            JSONObject exportResult = null;
            try {
                exportResult = JSONObject.parseObject(export.getBody());
                resultConvert(exportResult);
            } catch (Exception e) {
                throw new SimpleException("保存出错");
            }
            return exportResult;
        } catch (Exception e) {
        	return new Result("error", "操作失败，可能是验证码识别错误");
        }
    }
    
    private String getParamBody(TrafficInformation information, ContainerInfoList containerInfos) throws Exception {
        StringBuilder body = new StringBuilder();
        List<ContainerInfo> infoList = containerInfos.getContainerInfos();
        ContainerInfo info1 = infoList.get(0);
        ContainerInfo info2 = infoList.get(1);
        body.append("trailerNumberInfo.cntrNo=");
        if (StringUtils.isNotBlank(info1.getCntrno())) {
            if (StringUtils.isNotBlank(info2.getCntrno())) {
                body.append(URLEncoder.encode(info1.getCntrno(),"utf-8") + "%7C" +URLEncoder.encode( info2.getCntrno(),"utf-8") + "&");
            } else {
                body.append(URLEncoder.encode(info1.getCntrno(),"utf-8") + "&");
            }
        } else if (StringUtils.isNotBlank(info2.getCntrno())) {
            body.append(info2.getCntrno() + "&");
        } else {
            body.append("&");
        }
        body.append("trailerNumberInfo.sealno=");
        if (StringUtils.isNotBlank(info1.getSealno())) {
            if (StringUtils.isNotBlank(info2.getSealno())) {
                body.append(URLEncoder.encode(info1.getSealno(),"utf-8")  + "%7C" + URLEncoder.encode(info2.getSealno(),"utf-8")  + "&");
            } else {
                body.append(URLEncoder.encode(info1.getSealno(),"UTF-8") + "&");
            }
        } else if (StringUtils.isNotBlank(info2.getSealno())) {
            body.append(URLEncoder.encode(info2.getSealno(),"UTF-8") + "&");
        } else {
            body.append("&");
        }
        String[]informationParams=new String[]{"customsCode","msgStatus","addedFlag","yardCode","dockCode","corpname","corpno","vehicleno","trailerWeight",
                "rfidSerialno","trailerFrameWeight","tfcode1","tfcode","typedescription","remark"};
        Class<TrafficInformation> cl = TrafficInformation.class;
        for (String param:informationParams) {
            Field field = cl.getDeclaredField(param);
            if(!field.isAccessible()){
                field.setAccessible(true);
            }
            Object o = field.get(information);
            if(o==null){
                body.append("trailerNumberInfo."+param+"=&");
            }else {
                body.append("trailerNumberInfo."+param+"="+URLEncoder.encode(o.toString(),"UTF-8")+"&");
            }
        }
        if(StringUtils.isNotBlank(information.getBusinessType())){
            body.append("trailerNumberInfo.BusinessType=&");
        }else {
            body.append("trailerNumberInfo.BusinessType="+information.getBusinessType()+"&");
        }

        info1.setEirinfoExist("0");
        info2.setEirinfoExist("0");
        String[] containerParams=new String[]{"eirno","cntrno","sealno","sizetypeofcntr","cntrWeight"};
        Class<ContainerInfo> c2 = ContainerInfo.class;
        for (String param:containerParams) {
            Field field = c2.getDeclaredField(param);
            if(!field.isAccessible()){
                field.setAccessible(true);
            }
            Object o = field.get(info1);
            Object o1 = field.get(info2);
            if(o==null){
                body.append("containerInfo."+param+"=&");
            }else {
                body.append("containerInfo."+param+"="+URLEncoder.encode(o.toString(),"UTF-8")+"&");
            }
            if(o1==null){
                body.append("containerInfo."+param+"=&");
            }else {
                body.append("containerInfo."+param+"="+URLEncoder.encode(o1.toString(),"UTF-8")+"&");
            }
        }
        body.append("TrailsInfo=&Cno=&UserId=&CnoName=&");
        String result = body.toString();
        result=result.substring(0,result.length()-1);
        return result;
    }
    
}
